perm filename MARK[E,ALS] blob sn#257791 filedate 1977-01-18 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	MARKS XMARK XMPAGE XXADD XXSUB XPADD XPSUB XLALL XXARRL XXPAGE XXLINE
C00012 ENDMK
C⊗;
;MARKS XMARK XMPAGE XXADD XXSUB XPADD XPSUB XLALL XXARRL XXPAGE XXLINE

NMARKS←←27	;Max. no. of marks.

IMPURE

XXARRL:	0		;Holds line number at a page insertion or deletion
XXPAGE:	0		;Holds index value to MARKS at first entry for current page
XXLINE:	0		;Holds MARKS line number from first entry for current page
MARKS:	BLOCK NMARKS
	0		;Table stop
	-1		;Sure stop
PURE

XMARK:	TRNE B,2	;Is it a make or remove mark?
	JRST XMAKE	;Make (double-bucky)
	SKIPN MARKS	;Are there any marks?
	JRST XXNON1	;No
	PUSHJ P,GPAGL
	MOVS D,T	;Get into MARKS format
	CAMN D,MARKS	;Are we at the first mark?
	SKIPE MARKS+1	;And is it the only one?
	JRST XMARK1	;No
	OUTSTR [ASCIZ /
There is only one MARK and you are there! /]
	JRST PPJ1CR
XXNONE:	OUTSTR [ASCIZ / There are no marks! /]
	JRST POPJ1	;Here from αβ0αβM
XXNON1:	SORRY There are no marks!
	JRST POPJ1	;Here from αM
XFULL:	SORRY MARK table is full!
	JRST POPJ1
XTHERE:	OUTSTR [ASCIZ / Already marked! /]
	JRST POPJ1
XNOTF:	OUTSTR [ASCIZ / Not marked! /]
	JRST POPJ1

XMARK1:	MOVEI E,0
	TRNE F,NEG	;Backward search?
	JRST XBACK	;Yes
	CAML D,MARKS(E)	;Is D larger or equal to the largest?
	MOVEI D,0	;Yes so start over
	CAMGE D,MARKS+1(E)
	AOJA E,.-1	;Stops because marks block is terminated by a -1
	SOJLE A,XMOVE	;Do we need to go further?
	SOJGE E,.-1	;Back up another one
	AOJA E,.-5	;Woops, off upper end of table

XMOVE:	HLRZ A,MARKS(E)
	CAMG A,CURPAG
	CAMGE A,FIRPAG
	PUSHJ P,NEWPG0
	SUB A,FIRPAG
	JUMPE A,XMOVE1
	MOVEI G,XPLST
	HRRZ G,(G)
	JUMPE A,NEWPG4		;Use same error message (should never happen)
	SOJG A,.-2
	HLRZ A,2(G)
XMOVE1:	HRRZ G,MARKS(E)
	ADD A,G
	JRST SETARR

XBACK:	CAMG D,MARKS(E)
	AOJA E,.-1
	SKIPG MARKS(E)	;Is this a legitimate entry?
	MOVEI E,0	;No so go to the top of the list
	AOJGE A,XMOVE	;Do we need to go further?
	AOJA E,.-3	;Go down 1 and test if off bottom of active list

XMAKE:	TRNE F,ARG
	SKIPE A
	JRST XWRITE		;Not a clear command
	SKIPN MARKS		;Are there any marks?
	JRST XXNONE		;No
	TRNE F,NEG
	JRST XMARK0		;Clear MARKS on this page only
XZERO:	SETZM XXPAGE
	MOVE A,[XXPAGE,,XXLINE]
	BLT A,MARKS+NMARKS-1
	OUTSTR [ASCIZ / All marks have been cleared. /]
	JRST POPJ1

XWRITE:	PUSH P,E
	TRNE F,NEG		;Is it a delete?
	JRST XDELET		;Yes
	SKIPLE MARKS+NMARKS-1	;Is table full?
	JRST XFULL		;Yes
	PUSHJ P, GPAGL
	MOVS D,T
	MOVEI E,0
	CAMGE D,MARKS(E)
	AOJA E,.-1
	CAMG D,MARKS(E)
	JRST XTHERE		;A mark is already there
	EXCH D,MARKS(E)		;Make room
	SKIPLE D
	AOJA E,.-2
	POP P,E
	POPJ P,

XDELET:	PUSH P,E
	MOVEI E,0
	PUSHJ P,GPAGL
	MOVS D,T
XDEL2:	CAMGE D,MARKS(E)	;Find entry
	AOJA E,.-1		;Try again
	CAME D,MARKS(E)
	JRST XNOTF		;It was not marked
	HRRZS T
	HLRZ TT,MARKS-1(E)
	HLRZ D,MARKS+1(E)
	CAME TT,T
	CAMN TT,D
	SKIPA
	OUTSTR [ASCIZ/ Last Mark on this page was removed. /]
XDEL4:	MOVE D,MARKS+1(E)	;Close ranks
	MOVEM D,MARKS(E)
	SKIPE D
	AOJA E,XDEL4
	POP P,E
	POPJ P,

;New code to cancel marks on current page
XMARK0:	PUSH P,E
	MOVEI E,0
	PUSHJ P,GPAGL
	OUTSTR [ASCIZ/  MARKS on this page only have been cleared. /]
XMARKA:	HLRZ TT,MARKS(E)
	CAMGE TT,XXPAGE
	JRST XMARKC		;Before page of interest
	CAME TT,XXPAGE
	AOJA E,XMARKA
	PUSH P,E
XMARKB:	MOVE TT,MARKS+1(E)	;Close ranks after each deletion
	MOVEM TT,MARKS(E)
	SKIPLE TT
	AOJA E,XMARKB
	POP P,E
	JRST XMARKA

XMARKC:	POP P,E
	POPJ P,

;To handle a single line addition
XXADD:	PUSH P,T
	MOVEI TT,1
	PUSH P,TT
	PUSHJ P,XLALL
	POP P,T
	JRST POPTJ

;New code to handle deletions and additions
XLALL:	PUSH P,E
	PUSHJ P,GPAGL
	MOVEI E,0
	MOVE TT,-1(P)
;XLALL0:	HRRZM T,XXPAGE
;	HLRZM T,XXLINE
XLALL1:	HLRZ D,MARKS(E)
	CAMGE D,XXPAGE
	JRST XLALL2		;Before page of interest
	CAME D,XXPAGE
	AOJA E,XLALL1
	HRRZ D,MARKS(E)
	CAMGE D,XXLINE
	JRST XLALL2		;Before location of interest
	ADD D,TT
	CAMGE D,XXLINE
	MOVE D,XXLINE
	HRRM D,MARKS(E)
	AOJA E,XLALL1

XLALL2:	JUMPGE TT,XLALL4	;No duplications possible on an insertion
	MOVEI E,0
	MOVEI TT,1(E)
XLALL3:	MOVE T,MARKS(TT)
	CAMN T,MARKS(E)
	AOJA TT,XLALL3
	MOVEM T,MARKS+1(E)
	JUMPLE T,XLALL4
	AOS E
	AOJA TT,XLALL3

XLALL4:	POP P,E
	POPJ P,

;This routine handles page mark insertions
XPADD:	PUSH P,E
	MOVEI E,0
	PUSHJ P,GPAGL
	JRST XPADD2

XPADD1:	HLRZ T,MARKS(E)
	ADDI T,1	;Compensate for fact that CURPAG was upped 1 by insertion
	CAMGE T,XXPAGE
	JRST XPADD4
XPADD2:	CAME T,XXPAGE	;Is it on the split page?
	JRST XPADD3	;No, so only page value needs to be changed
	HRRZ T,MARKS(E)	;Now attend to line number
	SUB T,XXLINE	;Where is it with respect to insertion
	ADDI T,1
	JUMPLE T,XPADD4	;It was before so we are through
	HRRM T,MARKS(E)	;Fix line number
XPADD3:	MOVE T,[1,,0]
	ADDM T,MARKS(E)
	AOJA E,XPADD1	;Safe because table terminates with -1

XPADD4:	POP P,E
	POPJ P,

;This routine handles page mark deletions
XPSUB:	PUSH P,E
	PUSHJ P, GPAGL
	MOVEI E,0
	JRST XPSUB2

XPSUB1:	HLRZ T,MARKS(E)
	SUBI T,1	;Compensate for fact that CURPAG was decreased by deletion
	CAMGE T,XXPAGE
	JRST XPADD4	;The rest are OK.
XPSUB2:	CAME T,XXPAGE	;Is it on the ajoined portion?
	JRST XPSUB3	;No, so only page value needs to be changed
	MOVE T,XXLINE	;Line number on ajoined portion needs to be increased
	ADDM T,MARKS(E)	;Fix line number
XPSUB3:	MOVN T,[1,,0]
	ADDM T,MARKS(E)
	AOJA E,XPSUB1	;Safe because table terminates with -1